﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;

namespace Whu.BLM.News.Context
{
    public class NewsSystemContext : DbContext
    {
        public DbSet<User> Users { get; set; }
        public DbSet<News> News { get; set; }
        public DbSet<NewsCategory> NewsCategories { get; set; }
        public DbSet<Visit> Vis { get; set; }

        public NewsSystemContext(DbContextOptions options) : base(options)
        {

        }


        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<User>().ToTable("Users");
            modelBuilder.Entity<News>().ToTable("News");
            modelBuilder.Entity<NewsCategory>().ToTable("NewsCategory");
            modelBuilder.Entity<Visit>().ToTable("Visit");
        }
    }

    public enum UserGroup
    {
        User, Admin
    }

    public class User
    {
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }
        public string Username { get; set; }
        public string Passowrd { get; set; }
        public string Email { get; set; }
        public UserGroup UserGroup { get; set; } = UserGroup.User;
    }

    /// <summary>
    /// 查看记录
    /// </summary>
    public class Visit
    {
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }

        /// <summary>
        /// 查看用户
        /// </summary>
        public User User { get; set; }

        /// <summary>
        /// 被查看的新闻
        /// </summary>
        public News News { get; set; }
    }

    /// <summary>
    /// 新闻实体
    /// </summary>
    public class News
    {
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }

        /// <summary>
        /// 源URL。表示该新闻最初来源的URL，可以打开此URL看到新闻内容。
        /// </summary>
        public string OriginUrl { get; set; }

        /// <summary>
        /// 新闻标题
        /// </summary>
        public string Title { get; set; }

        /// <summary>
        /// 新闻摘要
        /// </summary>
        public string AbstractContent { get; set; }

        /// <summary>
        /// 新闻分类
        /// </summary>
        public NewsCategory Category { get; set; }
    }

    /// <summary>
    /// 新闻分类
    /// </summary>
    public class NewsCategory
    {
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }

        /// <summary>
        /// 分类名称
        /// </summary>
        public string Name { get; set; }
    }

}
